package Solution176_200;

import org.junit.Test;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

public class Solution190 {
    public int reverseBits(int n) {
        return Integer.reverse(n);
      /*  //转成二进制
        String binarySting = buildBinarySting(n);

        //生成10进制
        return getResult(binarySting);*/
    }

    private String buildBinarySting(int n) {
        StringBuilder builder = new StringBuilder();
        while (n != 0) {
            builder.append(n % 2);
            n = n / 2;
        }
        String s=builder.toString();
        for (int i = 0; i < 32 - s.length(); i++) {
            builder.append(0);
        }
        return builder.toString();
    }

    private int getResult(String binarySting) {
        long result = 0;
        for (int i = 0; i < binarySting.length(); i++) {
            result = result * 2 + Integer.parseInt(binarySting.charAt(i) + "");
        }
        return (int) result;
    }

    @Test
    public void test() {
      //  reverseBits(10);
        int result=getResult("10111111111111111111111111111111");
        System.out.println(result);
    }
}
